package cn.iocoder.yudao.module.system.controller.admin.hybase;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.service.hybase.HyBaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Tag(name = "数据同步")
@Slf4j
@RequestMapping("/system/sync")
@RestController
public class DataSyncController {

    @Resource
    HyBaseService hyBaseService;

    @Resource
    JdbcTemplate jdbcTemplate;

    /**
     * 创建Hybase表
     * @param tableName
     * @return
     */
    @GetMapping("/create/hybase/table")
    @Operation(summary = "创建Hybase表")
    public CommonResult<Boolean> createHyBaseTable(@RequestParam String tableName) {
        String sql = "SELECT COLUMN_NAME,DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ?";
        List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql, tableName);
        return CommonResult.success(hyBaseService.createTable(tableName, maps));
    }

    /**
     * 删除Hybase表
     * @param
     * @return
     */
    @GetMapping("/delete/hybase/tables")
    @Operation(summary = "删除Hybase表")
    public CommonResult<Boolean> deleteHyBaseTables(@RequestParam String tableName) {
        return CommonResult.success(hyBaseService.deleteTable(tableName));
    }


}
